import java.io.*;
public class Person implements Serializable
{
public final String name;
public final char gender;
public final int height, weight, goal;
public  final int CARB_RATIO_LOWER = 35;
public  final int CARB_RATIO_UPPER = 60;
public  final int FAT_RATIO_LOWER = 15;
public  final int FAT_RATIO_UPPER = 40;
public  final int PROTEIN_RATIO_LOWER = 10;
public  final int PROTEIN_RATIO_UPPER = 50;
int calories, carbs, fat, protein, exercise;
int points = 0;
boolean durationMultiplier = false;
public Person()
{
this.name = "";
this.gender = 'U';
this.height = 1;
this.weight = 100;
this.goal = 1500;
}
public Person(String name, char gender, int height, int weight, int goal)
{
this.name = name;
this.gender = gender;
this.height = height;
this.weight = weight;
this.goal = goal;
}

public void addFood(int calories, int carbs, int fat, int protein)
{
this.calories = calories;
this.carbs = carbs;
this.fat = fat;
this.protein = protein;
}
public void addExercise(int exercise, char duration)
{
	this.exercise = exercise;
	if (Character.toUpperCase(duration) == 'Y')
	this.durationMultiplier = true;
}
public int calculatePoints()
{

//Give Calorie based points.  Maximum 200, Minimum 0
	if (this.calories > goal * (2/3) && this.calories <= goal)
		{
			this.points += (1000-(this.goal - this.calories))/5;
		}
	else if (this.calories > goal && this.calories < this.goal + (this.goal*1/6))
		{
			this.points += (1000-(this.calories - this.goal)) / 7.5;
		}
	else if (this.calories > this.goal + (this.goal*1/6))
		{
			this.points -= (1000-(this.calories - this.goal)) / 20;
		}
		//bonus points if nutrients within target range
	if (this.carbs > CARB_RATIO_LOWER && this.carbs < CARB_RATIO_UPPER)
		{
			this.points += 25;
		}
	else
		{
			this.points -= 12;
		}
		
	if (this.fat > FAT_RATIO_LOWER && this.fat < FAT_RATIO_UPPER)
		{
			this.points += 15;
		}
	else
		{
			this.points -= 8;	
		}	
		
	if (this.protein > PROTEIN_RATIO_LOWER && this.protein < PROTEIN_RATIO_UPPER)
		{
			this.points += 10;
		}
	else
		{
			this.points -= 5;	
		}
		
//Calculate Exercise points, use multiplier if over 30 minutes
	if (durationMultiplier)
	this.points += exercise*1.2;
	else
	this.points += exercise;
/*Reset all food and exercise variables to 0 so more data can be added in the future
this.calories = 0;
this.fat = 0;
this.carbs = 0;
this.protein = 0;
this.exercise = 0;
this.durationMultiplier = false;*/
return points;
}

public void display()
{
System.out.println(points);
}
public void savePerson() throws Exception
{

ObjectOutputStream toStream;
toStream = new ObjectOutputStream(new FileOutputStream(this.name));
toStream.writeObject(this);
toStream.close();
}

public static Person loadPerson(String name) throws IOException, ClassNotFoundException
{
ObjectInputStream fromStream;
Person newPerson;
fromStream = new ObjectInputStream(new FileInputStream(name));
newPerson = (Person)fromStream.readObject();
fromStream.close();
return newPerson;

}
}
	
		
	
	